package com.example.smartcity.search;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;

import java.util.List;

public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.ViewHolder> {

    public List<Bitmap> bitmapList;

    public PhotoAdapter(List<Bitmap> bitmapList) {
        this.bitmapList = bitmapList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.photo_item, parent, false);
        return new ViewHolder(view);
    }
    public void updateData(List<Bitmap> newData) {
        Log.i("adapterbitmaplist",newData.get(0).toString());
        bitmapList.clear();
        bitmapList.addAll(newData);
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Bitmap fruit = bitmapList.get(position);
        holder.fruitImage.setImageBitmap(fruit);
    }

    @Override
    public int getItemCount() {
        return bitmapList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView fruitImage;

        public ViewHolder(View itemView) {
            super(itemView);
            fruitImage = itemView.findViewById(R.id.photorecycleadapter);
        }
    }
}